import com.javaee.interceptor.Utils.SqlSessionFactoryUtils;
import com.javaee.interceptor.entity.Shopping_Cart;
import com.javaee.interceptor.entity.goods;
import com.javaee.interceptor.entity.user;
import com.javaee.interceptor.entity.userVo;
import com.javaee.my.dao.userMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.SqlSessionUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import static com.javaee.my.user.BaseControllerApi.sqlsession;

public class mysqltest {
    private static userMapper usermapper;

    public static void main(String[] args) {
        SqlSessionFactory sqlSessionFactory = null;
        InputStream input = null;
        SqlSession session = null;

        //创建sqlSessionFactory
        try {

            input = Resources.getResourceAsStream("mybatis_config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(input);


        } catch (IOException e) {
            e.printStackTrace();
        }

        //得到SqlSession对象,执行查询操作
        try {
            session = sqlSessionFactory.openSession();
//            int count = session.selectOne("com.javaee.my.dao.userMapper.queryByUserName", "吴");
//            List<goods> res = session.selectList("com.javaee.my.dao.userMapper.queryAllgoods");
//            user uservo = new user(0,"龚","12345");
//             int res= session.insert("com.javaee.my.dao.userMapper.register", uservo);
            List<Shopping_Cart> Shopping_Cartlist=sqlsession.selectList(
                    "com.javaee.my.dao.businessMapper.select_Shopping_cartBy_id",1);
            System.out.println(Shopping_Cartlist);
             session.commit();
             session.close();
//            System.out.println(uservo.getId());
//            System.out.println(res);
        } finally {
            session.close();
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
